package com.lcj.workflow.bpmn.comment;

import com.lcj.common.exception.AochException;
import com.lcj.workflow.feign.OrderCommentApi;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.JavaDelegate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.HashMap;

@Component
public class UpdateDataService implements JavaDelegate {
    @Resource
    private OrderCommentApi orderCommentApi;

    @Transactional(propagation = Propagation.REQUIRED)
    public void execute(DelegateExecution adeDelegateExecution) {
        long commentId = Long.parseLong(adeDelegateExecution.getVariable("commentId", String.class));
        HashMap<Object, Object> hashMap = new HashMap<>();
        hashMap.put("rate", Integer.valueOf(5));
        hashMap.put("remark", null);
        hashMap.put("commentId", Long.valueOf(commentId));
        if (orderCommentApi.updateRateAndRemark(hashMap) != 1) {
            throw new AochException("更新订单评价分数和文字内容失败");
        }
        System.out.println("更新数据");
    }
}
